<?php

namespace app\admin\controller;

use think\Controller;
use think\facade\Request;
use app\admin\model\Goods as goodslist;
class Test extends Controller
{
    public function index(){
        return $this->fetch();
    }
    public function test(){
        // $data=db('goods')->select();
        $data=goodslist::select();
        // dump($data);
        return $this->fetch('test',['data'=>$data]);
    }
    public function read($id){
        $data=goodslist::find($id);
        // dump($data);
        return $this->fetch('read',['data'=>$data]);
    }
    public function add(){
        return $this->fetch('add');
    }
    public function save(){
        $data=Request::param();
        // dump($data);
        goodslist::create($data,true);
        // Db::table('goods')->insert();
        // $data=goodslist::select();
        // // dump($data);
        // return $this->fetch('test',['data'=>$data]);
        // $this->success('新增成功','test');
        $this->redirect('test');
    }
    public function search(){
        $param=Request::param('keyword');
        $data=goodslist::where('goods_name','like',"%$param%")->select();
        // dump($data);
        return $this->fetch('test',['data'=>$data]);
        // echo $param;
    }
    public function updata($id){
        $data=goodslist::where('id',$id)->find();
        // dump($data);
        return $this->fetch('updata',['data'=>$data]);
    }
    public function updata1($id){
        $data=Request::param();
        
        goodslist::where('id',$id)->update($data,true);
        $this->success('修改成功','test');
    }
    public function del($id){
        goodslist::where('id',$id)->delete();
        $this->redirect('test');
    }
}
